<?php

/**
 * CondoritoMateria filter form base class.
 *
 * @package    condorito
 * @subpackage filter
 * @author     Freddy Daniel Garcia
 */
abstract class BaseCondoritoMateriaFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'id_categoria'                       => new sfWidgetFormPropelChoice(array('model' => 'CondoritoCategoria', 'add_empty' => true)),
      'tipo'                               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'codigo'                             => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'nombre'                             => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'semestre'                           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'cupos'                              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'inscritos'                          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'cupos_disponibles'                  => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'horario'                            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'requisitos'                         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'id_profesor'                        => new sfWidgetFormPropelChoice(array('model' => 'CondoritoProfesor', 'add_empty' => true)),
      'token'                              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'condorito_estudiante_inscrita_list' => new sfWidgetFormPropelChoice(array('model' => 'CondoritoEstudiante', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'id_categoria'                       => new sfValidatorPropelChoice(array('required' => false, 'model' => 'CondoritoCategoria', 'column' => 'id')),
      'tipo'                               => new sfValidatorPass(array('required' => false)),
      'codigo'                             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'nombre'                             => new sfValidatorPass(array('required' => false)),
      'semestre'                           => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'cupos'                              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'inscritos'                          => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'cupos_disponibles'                  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'horario'                            => new sfValidatorPass(array('required' => false)),
      'requisitos'                         => new sfValidatorPass(array('required' => false)),
      'id_profesor'                        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'CondoritoProfesor', 'column' => 'id')),
      'token'                              => new sfValidatorPass(array('required' => false)),
      'condorito_estudiante_inscrita_list' => new sfValidatorPropelChoice(array('model' => 'CondoritoEstudiante', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('condorito_materia_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addCondoritoEstudianteInscritaListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(CondoritoEstudianteInscritaPeer::ID_MATERIA, CondoritoMateriaPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(CondoritoEstudianteInscritaPeer::ID_ESTUDIANTE, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(CondoritoEstudianteInscritaPeer::ID_ESTUDIANTE, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'CondoritoMateria';
  }

  public function getFields()
  {
    return array(
      'id'                                 => 'Number',
      'id_categoria'                       => 'ForeignKey',
      'tipo'                               => 'Text',
      'codigo'                             => 'Number',
      'nombre'                             => 'Text',
      'semestre'                           => 'Number',
      'cupos'                              => 'Number',
      'inscritos'                          => 'Number',
      'cupos_disponibles'                  => 'Number',
      'horario'                            => 'Text',
      'requisitos'                         => 'Text',
      'id_profesor'                        => 'ForeignKey',
      'token'                              => 'Text',
      'condorito_estudiante_inscrita_list' => 'ManyKey',
    );
  }
}
